/*
 * Tpdisenio2009App.java
 *
 */
package tpdisenio2009;

import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
import tpdisenio2009.model.beans.Administrator;
import tpdisenio2009.model.beans.Journalist;
import tpdisenio2009.model.beans.Person;
import tpdisenio2009.model.beans.User;
import tpdisenio2009.mvp.display.LoginViewImpl;
import tpdisenio2009.mvp.display.MainAdministratorViewImpl;
import tpdisenio2009.mvp.display.MainUserScreenViewImpl;
import tpdisenio2009.mvp.display.ManageTournamentDatePointsViewImpl2;
import tpdisenio2009.mvp.presenter.LoginPresenter;
import tpdisenio2009.mvp.presenter.MainAdministratorPresenter;
import tpdisenio2009.mvp.presenter.MainUserScreenPresenter;
import tpdisenio2009.mvp.presenter.ManageTournamentDatePointsPresenter;

public class Tpdisenio2009App extends SingleFrameApplication {

    public static Person loggedUser;

    /**
     * At startup create and show the main frame of the application.
     */
    @Override
    protected void startup() {
        LoginPresenter loginPresenter = new LoginPresenter(new LoginViewImpl(null, true));

//        while (true) {
            // Si no hay un usuario logueado abrir el login
            if (loggedUser == null) {
                loginPresenter.getView().asWidget().setVisible(true);
            }

            if (loggedUser != null) {
                if (loggedUser instanceof User) {
                    User user = (User) Tpdisenio2009App.loggedUser;
                    MainUserScreenViewImpl mainScreenView = new MainUserScreenViewImpl();
                    MainUserScreenPresenter mainScreenPresenter = new MainUserScreenPresenter(mainScreenView);
                    mainScreenPresenter.getView().asWidget().setVisible(true);

                } else if (loggedUser instanceof Journalist) {
                    System.err.println("JOURNALIST");
                    ManageTournamentDatePointsViewImpl2 managePointsView = new ManageTournamentDatePointsViewImpl2( null, true );
                    ManageTournamentDatePointsPresenter managePointsPresenter = new ManageTournamentDatePointsPresenter( managePointsView );
                    managePointsPresenter.getView().asWidget().setVisible( true );

                } else if (loggedUser instanceof Administrator) {
                    System.err.println("ADMINISTRATOR");
                    MainAdministratorViewImpl mainAdministratorView = new MainAdministratorViewImpl();
                    MainAdministratorPresenter mainAdministratorPresenter = new MainAdministratorPresenter( mainAdministratorView );
                    mainAdministratorPresenter.getView().asWidget().setVisible(true);
                }
            }
        //}
    }


//     }
    public static Tpdisenio2009App getApplication() {
        return Application.getInstance(Tpdisenio2009App.class);
    }

    public static void main(String[] args) {
        launch(Tpdisenio2009App.class, args);
    }
}
